// ==UserScript==
// @name          QuickOpen.uc.js
// @description   QuickOpen 快速打开指定选项
// @author         Runningcheese
// @namespace   http://www.runningcheese.com
// @include        main
// @license         MIT License
// @compatibility  Firefox 29+
// @charset        UTF-8
// @version        v2017.06.17 
// @homepage    http://www.runningcheese.com/firefox-v8
// ==/UserScript==

//载入脚本
function jsonToDOM(json, doc, nodes) {

    var namespaces = {
        html: 'http://www.w3.org/1999/xhtml',
        xul: 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'
    };
    var defaultNamespace = namespaces.html;

    function namespace(name) {
        var m = /^(?:(.*):)?(.*)$/.exec(name);        
        return [namespaces[m[1]], m[2]];
    }

    function tag(name, attr) {
        if (Array.isArray(name)) {
            var frag = doc.createDocumentFragment();
            Array.forEach(arguments, function (arg) {
                if (!Array.isArray(arg[0]))
                    frag.appendChild(tag.apply(null, arg));
                else
                    arg.forEach(function (arg) {
                        frag.appendChild(tag.apply(null, arg));
                    });
            });
            return frag;
        }

        var args = Array.slice(arguments, 2);
        var vals = namespace(name);
        var elem = doc.createElementNS(vals[0] || defaultNamespace, vals[1]);

        for (var key in attr) {
            var val = attr[key];
            if (nodes && key == 'id')
                nodes[val] = elem;

            vals = namespace(key);
            if (typeof val == 'function')
                elem.addEventListener(key.replace(/^on/, ''), val, false);
            else
                elem.setAttributeNS(vals[0] || '', vals[1], val);
        }
        args.forEach(function(e) {
            try {
                elem.appendChild(
                                    Object.prototype.toString.call(e) == '[object Array]'
                                    ?
                                        tag.apply(null, e)
                                    :
                                        e instanceof doc.defaultView.Node
                                        ?
                                            e
                                        :
                                            doc.createTextNode(e)
                                );
            } catch (ex) {
                elem.appendChild(doc.createTextNode(ex));
            }
        });
        return elem;
    }
    return tag.apply(null, json);
}


//定义按钮
CustomizableUI.createWidget({
    id: 'QuickOpen',
    defaultArea: CustomizableUI.AREA_NAVBAR,
    label: '快速打开',
    tooltiptext: '快速打开指定选项',
    onCreated: function(aNode) {
    aNode.setAttribute('type', 'menu');    
        
 //定义菜单      
        var myMenuJson = 
                                ['xul:menupopup', {id: 'QuickOpen_pop', position:'after_end'},
                                ['xul:menuitem', {label: '我的电脑',oncommand: 'QuickOpenMyComputer();',class:'menuitem-iconic', image:''}],
                                ['xul:menuitem', {label: '搜索文件',oncommand: 'EverythingSearch();',class:'menuitem-iconic', image:''}],
                                ['xul:menuitem', {label: '管理书签',oncommand: "PlacesCommandHook.showPlacesOrganizer('AllBookmarks');", class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '清理痕迹',oncommand: 'Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue).sanitize(window);',class:'menuitem-iconic', image:''}],  
                                 ['xul:menu', {label:'系统工具' ,class:'menu-iconic', image:''},
                               ['xul:menupopup', {},
                                ['xul:menuitem', {label: '音量控制',oncommand: 'QuickOpenVolume();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '记事本',oncommand: 'QuickOpenNotedpad();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '设置记事本',oncommand: 'Setnotepad2();',class:'menuitem-iconic', image:''}],
                                ['xul:menuitem', {label: '设置IDM',oncommand: 'SetIDM();',class:'menuitem-iconic', image:''}],
                                ['xul:menuitem', {label: '任务管理器',oncommand: 'QuickOpenTaskMGR();',class:'menuitem-iconic', image:''}],
                                ['xul:menuseparator', {}],
                                ['xul:menuitem', {label: '计算器',oncommand: 'QuickOpenCALC();',class:'menuitem-iconic', image:''}],
                                ['xul:menuitem', {label: '命令行',oncommand: 'QuickOpenCMD();',class:'menuitem-iconic', image:''}],
                                ['xul:menuitem', {label: '放大镜',oncommand: 'QuickOpenMagnify();',class:'menuitem-iconic', image:''}],
                                ['xul:menuitem', {label: '屏幕键盘',oncommand: 'QuickOpenOSK();',class:'menuitem-iconic', image:''}],
                                ['xul:menuitem', {label: 'IE浏览器',oncommand: 'QuickOpenIE();',class:'menuitem-iconic', image:''}],
                                ['xul:menuitem', {label: 'IE选项设置',oncommand: 'QuickOpenInetcpl();',class:'menuitem-iconic', image:''}],
                               ]
                               ],
                                ['xul:menu', {label:'常用功能' ,class:'menu-iconic', image:''},
                               ['xul:menupopup', {},
                               ['xul:menuitem', {label: '打开文件',oncommand: 'BrowserOpenFileWindow();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '隐私浏览',oncommand: 'OpenBrowserWindow({private: true});',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '历史记录',oncommand: 'PlacesCommandHook.showPlacesOrganizer("History");',class:'menuitem-iconic', image:''}],                        
                               ['xul:menuitem', {label: '故障排除',oncommand: 'var x = gBrowser.mCurrentTab._tPos + 1; gBrowser.moveTabTo(gBrowser.selectedTab =gBrowser.addTab("about:support"), x); ',class:'menuitem-iconic', image:''}],  
                               ['xul:menuitem', {label: '参数设置',oncommand: 'var x = gBrowser.mCurrentTab._tPos + 1; gBrowser.moveTabTo(gBrowser.selectedTab =gBrowser.addTab("about:config"), x); ',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '关于about',oncommand: 'var x = gBrowser.mCurrentTab._tPos + 1; gBrowser.moveTabTo(gBrowser.selectedTab =gBrowser.addTab("about:about"), x); ',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '编辑user.js',oncommand: 'QuickOpenUserjs();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '删除cookies',oncommand: 'window.openDialog("chrome://browser/content/preferences/cookies.xul");',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '关于浏览器',oncommand: 'openAboutDialog();',class:'menuitem-iconic', image:''}],
                               ]
                               ],['xul:menu', {label:'脚本更新' ,class:'menu-iconic', image:''},
                               ['xul:menupopup', {},
                               ['xul:menuitem', {label: '查看可用更新',oncommand: 'event.stopPropagation(); var x = gBrowser.mCurrentTab._tPos + 1; gBrowser.moveTabTo(gBrowser.selectedTab =gBrowser.addTab("http://git.oschina.net/runningcheese/firefox/raw/master/updatelog.txt"), x);',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: 'YoukuAntiADs.uc.js',oncommand: 'UpdateYoukuAntiADs();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '广告视频播放器更新',oncommand: 'UpdateYoukuAntiADsSWF();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: 'ButtonEventListener.uc.js',oncommand: 'UpdateButtonEventListener();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: 'QuickOpen.uc.js',oncommand: 'UpdateQuickOpen();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: 'QuickSnapshot.uc.js',oncommand: 'UpdateQuickSnapshot();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: 'QuickSwitch.uc.js',oncommand: 'UpdateQuickSwitch();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: 'QuickTranslate.uc.js',oncommand: 'UpdateQuickTranslate();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: 'SidebarMod.uc.js',oncommand: 'UpdateSidebarMod();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: 'SimpleMusicPlayer.uc.js',oncommand: 'UpdateSimpleMusicPlayer();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: 'TalkwithWallace.uc.js',oncommand: 'UpdateTalkwithWallace();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '_addmenu.js',oncommand: 'UpdateAddmenu();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '_keychanger.js',oncommand: 'UpdateKeychanger();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '_redirector.js',oncommand: 'UpdateRedirector();',class:'menuitem-iconic', image:''}],
                               ['xul:menuitem', {label: '_userAgentChange.js',oncommand: 'UpdateUserAgentChange();',class:'menuitem-iconic', image:''}],
                               ]
                               ],
                                ['xul:menuitem', {label: '配置文件夹',tooltiptext: 'Profiles', oncommand: 'var canvas = Components.classes["@mozilla.org/file/directory_service;1"].	getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsILocalFile).launch();',class:'menuitem-iconic', image:''}],
                                ['xul:menuitem', {label: '脚本文件夹',tooltiptext: 'Chrome', oncommand: 'var canvas = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("UChrm", Components.interfaces.nsILocalFile).reveal();',class:'menuitem-iconic', image:''}],
                                //['xul:menuitem', {label: '图片文件夹',tooltiptext: 'Images', oncommand: 'QuickOpenImages();',class:'menuitem-iconic', image:''}],
                                //['xul:menuitem', {label: '工具文件夹',tooltiptext: 'Software', oncommand: 'QuickOpenSoftware();',class:'menuitem-iconic', image:''}],     
                               ['xul:menuitem', {label: '火狐根目录', tooltiptext: 'Firefox', oncommand: 'QuickOpenApplication();',class:'menuitem-iconic', image:''}],     
                        ];
        aNode.appendChild(jsonToDOM(myMenuJson, aNode.ownerDocument, {}));
        aNode.setAttribute('menupopup', 'QuickOpen_pop');
    }
});


//定义图标
var cssStr = '@-moz-document url("chrome://browser/content/browser.xul"){'
		 + '#QuickOpen[cui-areatype="toolbar"] .toolbarbutton-icon {'
		 + 'list-style-image:url()'
		 + '}}'
     + '#QuickOpen[cui-areatype="menu-panel"] .toolbarbutton-icon, toolbarpaletteitem[place="palette"]> #QuickOpen .toolbarbutton-icon {'
		 + 'list-style-image:url()'
		 + '}}';
	var sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
	var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
	sss.loadAndRegisterSheet(ios.newURI("data:text/css;base64," + btoa(cssStr), null, null), sss.USER_SHEET);




//定义函数

function	QuickOpenImages() {var file = Services.dirsvc.get('ProfD', Ci.nsILocalFile); file.appendRelativePath("extensions\\userChromeJS_Mix@develop.com\\content\\images"); file.launch();};

function	QuickOpenSoftware() { var file = Services.dirsvc.get('UChrm', Ci.nsILocalFile); file.appendRelativePath("Local\\"); file.launch();};

function	QuickOpenApplication() { var path ="..\\..\\..\\..\\";	var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);file.initWithPath(path.replace(/^\./, Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path));file.launch();};

function	QuickOpenUserjs() { var file = Services.dirsvc.get('ProfD', Ci.nsILocalFile); file.appendRelativePath("user.js"); file.launch();};

function	EverythingSearch() { var file = Services.dirsvc.get('UChrm', Ci.nsILocalFile); file.appendRelativePath("Local\\Everything.exe"); file.launch();};

function	Setnotepad2() {  var file = Services.dirsvc.get('UChrm', Ci.nsILocalFile); file.appendRelativePath("Local\\NotePad2.bat"); file.launch();};

function	SetIDM() {	var file = Services.dirsvc.get('UChrm', Ci.nsILocalFile); file.appendRelativePath("Local\\IDM\\!绿化卸载.bat"); file.launch(); return file;};




 function QuickOpenMyComputer(event) {
			try {
				var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("WinD", Components.interfaces.nsILocalFile);
				file.append("explorer.exe");
				var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
				process.init(file);
				process.run(false, [","], 1);

			} catch (ex) {
				alert("打开我的电脑失败!")
			}
};


 function QuickOpenVolume(event) {
			try {
				var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("SysD", Components.interfaces.nsILocalFile);
				file.append(/6/.test(navigator.oscpu) ? "sndvol.exe" : "sndvol32.exe");
				var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
				process.init(file);
				process.run(false, ["-f"], 1);
			} catch (ex) {
				alert("打开音量控制器失败!")
			}
};


 function QuickOpenTaskMGR(event) {
			try {
				var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
				file.initWithPath(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("SysD", Components.interfaces.nsILocalFile).path + "\\taskmgr.exe");
				file.launch();
			} catch (ex) {
				alert("打开任务管理器失败!")
			}
};


 function QuickOpenIE(event) {
	try {
		var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProgF", Components.interfaces.nsILocalFile);
		file.append("Internet Explorer");
		file.append("iexplore.exe");
		var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
		process.init(file);
		process.run(false, ["about:Tabs"], 1);
	} catch (ex) {
		alert("打开IE失败!")
	}
}; 


 function QuickOpenNotedpad(event) {
			try {
				var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
				file.initWithPath(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("SysD", Components.interfaces.nsILocalFile).path + "\\notepad.exe");
				file.launch();
			} catch (ex) {
				alert("打开记事本失败!")
			}
};


 function QuickOpenInetcpl(event) {
			try {
				var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
				file.initWithPath(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("SysD", Components.interfaces.nsILocalFile).path + "\\inetcpl.cpl");
				file.launch();
			} catch (ex) {
				alert("打开Internet选项失败!")
			}
};

 function QuickOpenCALC(event) {
			try {
				var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
				file.initWithPath(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("SysD", Components.interfaces.nsILocalFile).path + "\\calc.exe");
				file.launch();
			} catch (ex) {
				alert("打开计算器失败!")
			}
};

 function QuickOpenCMD(event) {
			try {
				var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
				file.initWithPath(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("SysD", Components.interfaces.nsILocalFile).path + "\\cmd.exe");
				file.launch();
			} catch (ex) {
				alert("打开命令行失败!")
			}
};

 function QuickOpenOSK(event) {
			try {
				var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
				file.initWithPath(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("SysD", Components.interfaces.nsILocalFile).path + "\\osk.exe");
				file.launch();
			} catch (ex) {
				alert("打开屏幕键盘失败!")
			}
};

 function QuickOpenMagnify(event) {
			try {
				var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
				file.initWithPath(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("SysD", Components.interfaces.nsILocalFile).path + "\\magnify.exe");
				file.launch();
			} catch (ex) {
				alert("打开放大镜失败!")
			}
};

function UpdateYoukuAntiADs(event) {
//更新视频广告过滤脚本
        var url = 'http://git.oschina.net/runningcheese/firefox/raw/master/YoukuAntiADs.uc.js';
        var uri = Services.io.newURI(url, null, null);

        var target = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("ProfD", Components.interfaces.nsIFile);
        target.append("chrome");
        target.append("SubScript");
        target.append("YoukuAntiADs.uc.js");

        var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
        persist.persistFlags = persist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
        persist.progressListener = {
            onProgressChange: function() {
            },
            onStateChange: function(aWebProgress, aRequest, flags, status) {
                if((flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
                    if (userChromejs.save) {
                        userChromejs.save.showInstallMessage('脚本YoukuAntiADs.uc.js', '已成功更新');
                    }
                }
            }
        };
        persist.saveURI(uri, null, null, null, null, null, target, null);
    };



function UpdateYoukuAntiADsSWF(event) {
//更新视频广告过滤播放器
	var file = Services.dirsvc.get('UChrm', Ci.nsILocalFile);
	file.appendRelativePath("Local\\UpdateYoukuAntiADs.bat");
	file.launch(); return file;
    };




function UpdateButtonEventListener(event) {
        var url = 'http://git.oschina.net/runningcheese/firefox/raw/master/ButtonEventListener.uc.js';
        var uri = Services.io.newURI(url, null, null);

        var target = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("ProfD", Components.interfaces.nsIFile);
        target.append("chrome");
        target.append("SubScript");
        target.append("ButtonEventListener.uc.js");

        var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
        persist.persistFlags = persist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
        persist.progressListener = {
            onProgressChange: function() {
            },
            onStateChange: function(aWebProgress, aRequest, flags, status) {
                if((flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
                    if (userChromejs.save) {
                        userChromejs.save.showInstallMessage('脚本ButtonEventListener.uc.js', '已成功更新');
                    }
                }
            }
        };
        persist.saveURI(uri, null, null, null, null, null, target, null);
    };



function UpdateQuickOpen(event) {
        var url = 'http://git.oschina.net/runningcheese/firefox/raw/master/QuickOpen.uc.js';
        var uri = Services.io.newURI(url, null, null);

        var target = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("ProfD", Components.interfaces.nsIFile);
        target.append("chrome");
        target.append("SubScript");
        target.append("QuickOpen.uc.js");

        var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
        persist.persistFlags = persist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
        persist.progressListener = {
            onProgressChange: function() {
            },
            onStateChange: function(aWebProgress, aRequest, flags, status) {
                if((flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
                    if (userChromejs.save) {
                        userChromejs.save.showInstallMessage('脚本QuickOpen.uc.js', '已成功更新');
                    }
                }
            }
        };
        persist.saveURI(uri, null, null, null, null, null, target, null);
    };




function UpdateQuickSnapshot(event) {
        var url = 'http://git.oschina.net/runningcheese/firefox/raw/master/QuickSnapshot.uc.js';
        var uri = Services.io.newURI(url, null, null);

        var target = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("ProfD", Components.interfaces.nsIFile);
        target.append("chrome");
        target.append("SubScript");
        target.append("QuickSnapshot.uc.js");

        var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
        persist.persistFlags = persist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
        persist.progressListener = {
            onProgressChange: function() {
            },
            onStateChange: function(aWebProgress, aRequest, flags, status) {
                if((flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
                    if (userChromejs.save) {
                        userChromejs.save.showInstallMessage('脚本QuickSnapshot.uc.js', '已成功更新');
                    }
                }
            }
        };
        persist.saveURI(uri, null, null, null, null, null, target, null);
    };




function UpdateQuickSwitch(event) {
        var url = 'http://git.oschina.net/runningcheese/firefox/raw/master/QuickSwitch.uc.js';
        var uri = Services.io.newURI(url, null, null);

        var target = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("ProfD", Components.interfaces.nsIFile);
        target.append("chrome");
        target.append("SubScript");
        target.append("QuickSwitch.uc.js");

        var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
        persist.persistFlags = persist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
        persist.progressListener = {
            onProgressChange: function() {
            },
            onStateChange: function(aWebProgress, aRequest, flags, status) {
                if((flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
                    if (userChromejs.save) {
                        userChromejs.save.showInstallMessage('脚本QuickSwitch.uc.js', '已成功更新');
                    }
                }
            }
        };
        persist.saveURI(uri, null, null, null, null, null, target, null);
    };






function UpdateQuickTranslate(event) {
        var url = 'http://git.oschina.net/runningcheese/firefox/raw/master/QuickTranslate.uc.js';
        var uri = Services.io.newURI(url, null, null);

        var target = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("ProfD", Components.interfaces.nsIFile);
        target.append("chrome");
        target.append("SubScript");
        target.append("QuickTranslate.uc.js");

        var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
        persist.persistFlags = persist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
        persist.progressListener = {
            onProgressChange: function() {
            },
            onStateChange: function(aWebProgress, aRequest, flags, status) {
                if((flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
                    if (userChromejs.save) {
                        userChromejs.save.showInstallMessage('脚本QuickTranslate.uc.js', '已成功更新');
                    }
                }
            }
        };
        persist.saveURI(uri, null, null, null, null, null, target, null);
    };






function UpdateSidebarMod(event) {
        var url = 'http://git.oschina.net/runningcheese/firefox/raw/master/SidebarMod.uc.js';
        var uri = Services.io.newURI(url, null, null);

        var target = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("ProfD", Components.interfaces.nsIFile);
        target.append("chrome");
        target.append("SubScript");
        target.append("SidebarMod.uc.js");

        var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
        persist.persistFlags = persist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
        persist.progressListener = {
            onProgressChange: function() {
            },
            onStateChange: function(aWebProgress, aRequest, flags, status) {
                if((flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
                    if (userChromejs.save) {
                        userChromejs.save.showInstallMessage('脚本SidebarMod.uc.js', '已成功更新');
                    }
                }
            }
        };
        persist.saveURI(uri, null, null, null, null, null, target, null);
    };



function UpdateSimpleMusicPlayer(event) {
        var url = 'http://git.oschina.net/runningcheese/firefox/raw/master/SimpleMusicPlayer.uc.js';
        var uri = Services.io.newURI(url, null, null);

        var target = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("ProfD", Components.interfaces.nsIFile);
        target.append("chrome");
        target.append("SubScript");
        target.append("SimpleMusicPlayer.uc.js");

        var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
        persist.persistFlags = persist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
        persist.progressListener = {
            onProgressChange: function() {
            },
            onStateChange: function(aWebProgress, aRequest, flags, status) {
                if((flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
                    if (userChromejs.save) {
                        userChromejs.save.showInstallMessage('脚本SimpleMusicPlayer.uc.js', '已成功更新');
                    }
                }
            }
        };
        persist.saveURI(uri, null, null, null, null, null, target, null);
    };





function UpdateTalkwithWallace(event) {
        var url = 'http://git.oschina.net/runningcheese/firefox/raw/master/TalkwithWallace.uc.js';
        var uri = Services.io.newURI(url, null, null);

        var target = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("ProfD", Components.interfaces.nsIFile);
        target.append("chrome");
        target.append("SubScript");
        target.append("TalkwithWallace.uc.js");

        var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
        persist.persistFlags = persist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
        persist.progressListener = {
            onProgressChange: function() {
            },
            onStateChange: function(aWebProgress, aRequest, flags, status) {
                if((flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
                    if (userChromejs.save) {
                        userChromejs.save.showInstallMessage('脚本TalkwithWallace.uc.js', '已成功更新');
                    }
                }
            }
        };
        persist.saveURI(uri, null, null, null, null, null, target, null);
    };






function UpdateAddmenu(event) {
        var url = 'http://git.oschina.net/runningcheese/firefox/raw/master/_addmenu.js';
        var uri = Services.io.newURI(url, null, null);

        var target = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("ProfD", Components.interfaces.nsIFile);
        target.append("chrome");
        target.append("Local");
        target.append("_addmenu.js");

        var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
        persist.persistFlags = persist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
        persist.progressListener = {
            onProgressChange: function() {
            },
            onStateChange: function(aWebProgress, aRequest, flags, status) {
                if((flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
                    if (userChromejs.save) {
                        userChromejs.save.showInstallMessage('脚本_addmenu.js', '已成功更新');
                    }
                }
            }
        };
        persist.saveURI(uri, null, null, null, null, null, target, null);
    };




function UpdateKeychanger(event) {
        var url = 'http://git.oschina.net/runningcheese/firefox/raw/master/_keychanger.js';
        var uri = Services.io.newURI(url, null, null);

        var target = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("ProfD", Components.interfaces.nsIFile);
        target.append("chrome");
        target.append("Local");
        target.append("_keychanger.js");

        var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
        persist.persistFlags = persist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
        persist.progressListener = {
            onProgressChange: function() {
            },
            onStateChange: function(aWebProgress, aRequest, flags, status) {
                if((flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
                    if (userChromejs.save) {
                        userChromejs.save.showInstallMessage('脚本_keychanger.js', '已成功更新');
                    }
                }
            }
        };
        persist.saveURI(uri, null, null, null, null, null, target, null);
    };





function UpdateRedirector(event) {
        var url = 'http://git.oschina.net/runningcheese/firefox/raw/master/_redirector.js';
        var uri = Services.io.newURI(url, null, null);

        var target = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("ProfD", Components.interfaces.nsIFile);
        target.append("chrome");
        target.append("Local");
        target.append("_redirector.js");

        var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
        persist.persistFlags = persist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
        persist.progressListener = {
            onProgressChange: function() {
            },
            onStateChange: function(aWebProgress, aRequest, flags, status) {
                if((flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
                    if (userChromejs.save) {
                        userChromejs.save.showInstallMessage('脚本_redirector.js', '已成功更新');
                    }
                }
            }
        };
        persist.saveURI(uri, null, null, null, null, null, target, null);
    };




function UpdateUserAgentChange(event) {
        var url = 'http://git.oschina.net/runningcheese/firefox/raw/master/_userAgentChange.js';
        var uri = Services.io.newURI(url, null, null);

        var target = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("ProfD", Components.interfaces.nsIFile);
        target.append("chrome");
        target.append("Local");
        target.append("_userAgentChange.js");

        var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
        persist.persistFlags = persist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
        persist.progressListener = {
            onProgressChange: function() {
            },
            onStateChange: function(aWebProgress, aRequest, flags, status) {
                if((flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
                    if (userChromejs.save) {
                        userChromejs.save.showInstallMessage('脚本_userAgentChange.js', '已成功更新');
                    }
                }
            }
        };
        persist.saveURI(uri, null, null, null, null, null, target, null);
    };







